/*
 * Network.java
 * Some tool
 * 
 * */


package wps.servicebus;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;



public class Network {
	public static class Protocol {
		public static String createRequest(String URL, String params){
			return URL + params;
		}
		public static int parseQuitMessage(String message){
			String[] messages = message.split(",");
//			System.out.println(messages[0]);
//			System.out.println(messages[1]);
			if(messages[0].equals("quit")){
				return Integer.parseInt(messages[1]);
			} else{
				return -1;
			}
			
		}
	}
	
	public static boolean isPortAvailable(int port){
		try {
			ServerSocket socket = new ServerSocket(port);
			socket.close();
			return true;			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			return false;
		}			
	}
	
	public static String getHttpURL(String addr, int port){
		return "http://" + addr + ":" + port + "/";
	}
}
